import 'package:flutter/material.dart';
import '../../model/conversation.dart';
import 'conversation_item.dart';

class UIConversationList extends StatefulWidget {
  UIConversationList({Key? key}) : super(key: key);

  Function(Conversation item)? onPress;

  @override
  _UiChatlistState createState() => _UiChatlistState();
}

class _UiChatlistState extends State<UIConversationList> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        toolbarHeight: 35,
        shadowColor: Colors.transparent,
        title: const Text(
          '消息',
          style: TextStyle(color: Colors.white, fontSize: 18),
        ),
        actions: [],
      ),
      // ignore: avoid_unnecessary_containers
      body: MessagePage(this.widget),
    );
  }
}

class MessagePage extends StatelessWidget {
  UIConversationList ui;

  MessagePage(this.ui) {}

  var length = Conversation.mockConversations.length + 0;

  @override
  Widget build(BuildContext context) {
    return Container(
        child: ListView.builder(
      itemBuilder: (BuildContext context, int index) {
        return ConversationItem(
          Conversation.mockConversations[index],
          index,
          0,
          ui.onPress,
        );
      },
      itemCount: length,
    ));
  }
}
